from django.utils.deprecation import MiddlewareMixin


class TestMiddleware1(MiddlewareMixin):
    def process_request(self, request):
        print('process_request1被调用')

    def process_view(self, request, view_func, view_args, view_kwargs):
        # 处理视图前自动调用
        request.hehe = 'haha'
        print('process_view1 被调用')

    def process_response(self, request, response):
        """在每个响应返回给客户端之前自动调用"""
        print('process_response1 被调用')
        return response

class TestMiddleware2(MiddlewareMixin):
    def process_request(self, request):
        print('process_request2被调用')

    def process_view(self, request, view_func, view_args, view_kwargs):
        # 处理视图前自动调用
        request.hehe = 'haha'
        print('process_view2 被调用')

    def process_response(self, request, response):
        """在每个响应返回给客户端之前自动调用"""
        print('process_response2 被调用')
        return response